<template>
  <!--勘察单位新增弹层start -->
  <el-dialog
    v-dialogDrag
    :title="dialogTitle"
    :close-on-click-modal="false"
    :visible.sync="dialogVisible"
    class="dialogStyleMiddle"
    :before-close="cancel"
  >
    <el-form :inline="true">
      <el-form-item label="勘察单位">
        <el-input
          v-model="filters.name"
          size="medium"
          class="serach-person"
          placeholder="请输入勘察单位名称"
        />
        <el-button size="medium" type="primary" @click="getList">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table
      ref="multipleTable"
      :data="tableData"
      style="width: 100%;"
      stripe
      class="table-list"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="name" label="企业名称" min-width="150" align="center" />
      <el-table-column prop="sysEnterpriseType" label="企业类型" width="180" align="center">
        <template slot-scope="{row}">
          <span v-if="row.sysEnterpriseType === '04'">勘察单位</span>
        </template>
      </el-table-column>
      <el-table-column prop="creditCodePic" :show-overflow-tooltip="true" label="信用代码" width="180" align="center" />
    </el-table>
    <pagination
      :total="total"
      :page.sync="filters.pageNum"
      :limit.sync="filters.pageSize"
      :page-sizes="[8,15,20,50,100]"
      :page-count="filters.pageCount"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <DialogFooter />
    </div>
  </el-dialog>
</template>

<script>

import { addInspectoUnit } from '@/api/projectManage/projectData'
import { listSurveyUnit } from '@/api/projectManage/projectData'
import DialogFooter from '@/components/Common/Btns/DialogFooter/index'
export default {
  components: {
    DialogFooter
  },
  data() {
    return {
      // 选择的单位
      multipleSelection: [],
      // 筛选勘察单位
      filters: {
        pageNum: 1,
        pageSize: 8,
        pageCount: 5,
        name: '',
        sysEnterpriseType: '04'
      },
      // 勘察单位列表
      tableData: [],
      proId: '',
      total: 0,
      /* 新增 start*/
      dialogTitle: '', // 弹层标题
      dialogVisible: false, // 弹层是否显示
      btnDisabled: false // 确定按钮
      // 表单验证规则
    }
  },
  methods: {
    /* 新增/编辑弹层 start*/
    // 新增/编辑
    handleAdd(title, proId) {
      this.dialogTitle = title
      this.dialogVisible = true
      this.proId = proId
      this.getList()
    },
    // 筛选人员
    getList() {
      listSurveyUnit(this.filters).then(res => {
        const { data: { rows, total }} = res
        this.tableData = rows
        this.total = total
      })
    },
    // 添加企业
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 取消按钮
    cancel() {
      this.dialogVisible = false
      this.btnDisabled = false
      this.emptyAddForm()
    },
    // 提交按钮
    async submitForm() {
      const { multipleSelection, proId } = this
      if (multipleSelection.length) {
        const newArr = multipleSelection.map(item => ({ nodeId: item.id, proId }))
        await addInspectoUnit(newArr)
        this.msgSuccess('分配成功!')
      }
      this.cancel()
    },
    // 表单重置
    emptyAddForm() {
      this.resetForm('addForm')
      this.multipleSelection = []
    }
    /* 新增弹层 end*/
  }
}
</script>

<style scoped>
</style>
